﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="BottleAnalyseRes.aspx.cs" Inherits="PMS.UI.PM.BottleAnalyseRes" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var LabelUrl;
        var CertificateUrl;
        $(function () {
            $("#btnSave").linkbutton('enable');
            $("#btnReset").linkbutton('enable');
            $("#btnCheck").linkbutton('enable');
            var rowData;
            var height = $("#divTotal").height();
            var content = parseFloat(height) - 150;
            $("#tbList").css("height", content);

           
            $("#SweepCode").focus();
            //Jquery监听扫码枪回车事件
            $("#SweepCode").keyup(function (event) {
                if (event.keyCode == 13) {
                    var code = $(this).val();
                    code = code.replace(/\n/g, "")
                    $(this).val("");
                    LoadTable("", code)
                }
            });
            //通过分析模块内部进入，传了ID
            var id = com.get.ID;
            if (id != undefined) {
                LoadTable(id, "")
            }
        });
    </script>
    <script type="text/javascript">
        function LoadTable(id, barCode) {
            $("#btnSave").linkbutton('enable');
            $("#btnReset").linkbutton('enable');
            $("#btnCheck").linkbutton('enable');
            //根据气瓶状态设置按钮权限
            var action = com.get.action;

            if (action == "view") {
                //$("#btnSave").linkbutton('disable');
                $("#btnReset").linkbutton('disable');
                $("#btnCheck").linkbutton('disable');
            }

            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/Logic/PM/BottleAnalyseAjax.aspx?method=GetBottleAnalyseByIDCode",
                data: { 'ID': id, 'BarCode': barCode },
                success: function (data) {
                    $("#form1").form("load", data);
                    LabelUrl = data.LabelUrl;
                    CertificateUrl = data.CetificateUrl;
                    //已经分析过了或者已经发货了
                    if (data.AnalyseRes == '0' || data.AnalyseRes == '1' || $("#State").val() == '3') {
                        //$("#btnSave").linkbutton('disable');
                        $("#btnReset").linkbutton('disable');
                        $("#btnCheck").linkbutton('disable')
                    }
                    if ($("#State").val() == '0') {
                        com.message("error", "当前气瓶还未完成配气，无法进行分析");
                        //$("#btnSave").linkbutton('disable');
                        $("#btnReset").linkbutton('disable');
                        $("#btnCheck").linkbutton('disable');
                        $("#btnPrintLabel").linkbutton('disable');
                        $("#btnPrintCert").linkbutton('disable');
                    }
                }
            });

            $("#tbList").datagrid({
                url: '/Logic/PM/BottleAnalyseAjax.aspx?method=GetBottleAnalyseRes',
                queryParams: { 'ID': id, 'BarCode': barCode },
                loadMsg: '数据加载中请稍后……',
                rownumbers: true,
                idField: "ID",
                lines: true,
                // fitColumns:true,
                columns: [[
                    {
                        field: 'ck', checkbox: true, width: 30
                    },
                    //{
                    //    field: 'ID', title: 'ID', width: 50, align: "center"
                   // },
                    {
                        field: 'GasChiName', title: '气体名称', width: 80, align: "center"
                    },
                    
                     {
                         field: 'BudgetConcentration', title: '客户浓度(ppm)', width: 100, align: "center",
                         formatter: function (value, row, index) {
                             return (value * 10000).toFixed(2);
                         }
                     },
                     {
                         field: 'CusConcUnit', title: '客户带单位浓度', width: 100, align: "center"
                     },

                      {
                          field: 'Tolerance', title: '误差容忍度(ppm)', align: "center", width: 100
                      },
                    {
                        field: 'Concentration', title: '计算浓度(ppm)', width: 100, align: "center",
                        formatter: function (value, row, index) {
                            return (value * 10000).toFixed(2);
                        }
                    },
                    {
                        field: 'AnalyseConcentration', title: '分析浓度(ppm)', width: 100, align: "center",
                        formatter: function (value, row, index) {
                            if (value == null) value = 0;
                            return "<input id='AnalyseConcentration' name='AnalyseConcentration'  value='" + (value * 10000).toFixed(2) + "'  style='width:90px' />";
                        }
                    },
                    {
                        field: 'AnalyseMethod', title: '分析方法', width: 180, align: "center",
                        formatter: function (value, row, index) {
                            if (value == null) value = "";
                            return "<input id='AnalyseMethod' name='AnalyseMethod'  value='" + value + "'  style='width:170px' />";
                        }
                    },
                    {
                        field: 'AnalyseFile', title: '分析文件名称', width: 100, align: "center",
                        formatter: function (value, row, index) {
                            if (value == null) value = "";
                            return "<input id='AnalyseFile' name='AnalyseFile'  value='" + value + "'  style='width:90px' />";
                        }
                    },
                     {
                         field: 'PrintUnit', title: '打印单位', width: 80, align: "center",
                         formatter: function (value, row, index) {
                             if (value == null) value = '0';
                             return "<input id='PrintUnit' name='PrintUnit'  value='" + value + "'  style='width:70px' />";
                         }
                     },
                      {
                          field: 'PrintConcentration', title: '打印浓度', width: 90, align: "center",
                          formatter: function (value, row, index) {
                              if (value == null) value = '1';
                              return "<input id='PrintConcentration' name='PrintConcentration'  value='" + value + "'  style='width:80px' />";
                          }
                      },
                      {
                          field: 'PrintDigitNum', title: '打印位数', width: 60, align: "center",
                          formatter: function (value, row, index) {
                              if (value == null) value = '3';
                              return "<input id='PrintDigitNum' name='PrintDigitNum'  value='" + value + "'  style='width:50px' />";
                          }
                      },
                      {
                          field: 'AnalStandardConc', title: '标准气浓度', width: 80, align: "center",
                          formatter: function (value, row, index) {
                              if (value == null) value = '0';
                              return "<input id='AnalStandardConc' name='AnalStandardConc'  value='" + value + "'  style='width:50px' />%";
                          }
                      },
                      {
                          field: 'AnalStandardBottleCode', title: '标准气瓶号', width: 80, align: "center",
                          formatter: function (value, row, index) {
                              if (value == null) value = '';
                              return "<input id='AnalStandardBottleCode' name='AnalStandardBottleCode'  value='" + value + "'  style='width:70px' />";
                          }
                      },
                    {
                        field: 'AnalyseNote', title: '备注', sortable: false, width: 100, align: "center",
                        formatter: function (value, row, index) {
                            if (value == null) value = "";
                            return "<input id='AnalyseNote' name='AnalyseNote'  value='" + value + "'  style='width:90px' />";
                        }
                    },
                    {
                        field: 'GasEngName', title: '分子式', width: 100, align: "center"
                    },
                    {
                        field: 'GasWeight', title: '分子量', width: 60, align: "center"
                    },

                ]],
                singleSelect: true,
                striped: true,
                onLoadSuccess: function () {
                    $("input[name=AnalyseMethod]").combobox({
                        data: StaticCombo.AnalyseMethod,
                        valueField: "text",
                        textField: "text"
                    });
                    $("input[name=PrintUnit]").combobox({
                        data: [{
                            text: 'mol/mol',
                            value: '0'
                        }, {
                            text: 'mg/m3',
                            value: '1'
                        }],
                        valueField: "value",
                        textField: "text"
                    });
                    $("input[name=PrintConcentration]").combobox({
                        data: [{
                            text: '计算浓度',
                            value: '0'
                        }, {
                            text: '分析浓度',
                            value: '1'
                        }],
                        valueField: "value",
                        textField: "text"
                    });
                }
            });

        }

    </script>
    <script>

        //保存
        function funcSave() {
            var arr = GetTableData();
            var res = $('#AnalyseRes').combobox('getValue');
            
            com.ajax({
                data: { 'Detail': JSON.stringify(arr) , 'AnalyseRes':res},
                url: "/Logic/PM/BottleAnalyseAjax.aspx?method=EditAnalyseRes",
                success: function (data) {
                    com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })

                }
            })
        }

        //重置
        function funcReload() {
            $("#tbList").datagrid("reload");
        }

        //分析完成
        function funcCheck() {
            funcSave();
            var isQualified = false;
            $.extend($.messager.defaults, {
                ok: "合格",
                cancel: "不合格"
            });
            $.messager.confirm('判定合格', '该瓶气体是否合格？', function (r) {
                if (r) {
                    isQualified = true;
                }
                var bottleSerialCode = $('#SerialCode').val();
                if (bottleSerialCode != "") {
                    com.ajax({
                        url: '/Logic/PM/BottleAnalyseAjax.aspx?method=CheckBottleGas',
                        data: { 'BarCode': bottleSerialCode, 'res': isQualified },
                        success: function (data) {
                            com.message(data.state, data.msg, function () {
                                $.ajax({
                                    type: "POST",
                                    dataType: "json",
                                    url: "/Logic/PM/BottleAnalyseAjax.aspx?method=GetBottleAnalyseByIDCode",
                                    data: { 'ID': "", 'BarCode': bottleSerialCode },
                                    success: function (data) {
                                        $("#form1").form("load", data);
                                       // $("#btnSave").linkbutton('disable');
                                        $("#btnReset").linkbutton('disable');
                                        $("#btnCheck").linkbutton('disable');
                                    }
                                });
                            })
                        }
                    });
                }
            });
        }

        function funcPrintLabel(temp) {
            var analRes = $('#AnalyseRes').combobox('getValue');
            if (analRes == '2' || analRes == undefined) {
                com.message('error', '当前气瓶还未分析完成，请判定是否合格后再打印');
                return;
            }

            if (analRes == '1' ) {
                com.message('error', '当前气瓶分析结果为不合格，无法打印标签');
                return;
            }
            //var Id = com.get.ID
            //if (Id == undefined) {
            //    Id = $('#ID').val();
            //}
            var Id = $('#ID').val();
            switch (temp) {
                case 1:
                    top.wrapper.addTab("打印标签", "/UI/PM/PrintLabel.aspx?action=print&Id=" + Id);
                    break;
                case 2:
                    top.wrapper.addTab("打印标签", "/UI/PM/PrintLabel2.aspx?action=print&Id=" + Id);
                    break;
                case 3:
                    top.wrapper.addTab("打印标签", "/UI/PM/PrintLabel3.aspx?action=print&Id=" + Id);
                    break;
                case 4:
                    top.wrapper.addTab("打印标签", "/UI/PM/PrintLabel4.aspx?action=print&Id=" + Id);
                    break;
                case 5:
                    top.wrapper.addTab("打印标签", "/UI/PM/PrintLabel5.aspx?action=print&Id=" + Id);
                    break;
                default:
            }

        }

        function funcPrintRecord(temp) {
            //var Id = com.get.ID
            //if (Id == undefined) {
            //    Id = $('#ID').val();
            //}
            var Id = $('#ID').val();
            switch (temp) {
                case 1:
                    if (LabelUrl != null && LabelUrl != "") {
                        top.wrapper.addTab("标签记录", "/UI/PM/" + LabelUrl + ".aspx?action=record&Id=" + Id);
                    }
                    else {
                        com.message('error', '当前气体暂无打印记录！');
                    }

                    break;
                case 2:
                    if (CertificateUrl != null && CertificateUrl != "") {
                        top.wrapper.addTab("证书记录", "/UI/PM/" + CertificateUrl + ".aspx?action=record&Id=" + Id);
                    }
                    else {
                        com.message('error', '当前气体暂无打印记录！');
                    }

                    break;
                default:
            }
        }


        function funcPrintCert() {
            var analRes = $('#AnalyseRes').combobox('getValue');
            if (analRes == '2' || analRes == undefined) {
                com.message('error', '当前气瓶还未分析完成，请判定是否合格后再打印');
                return;
            }

            if (analRes == '1') {
                com.message('error', '当前气瓶分析结果为不合格，无法打印证书');
                return;
            }
            //var Id = com.get.ID
            //if (Id == undefined) {
            //    Id = $('#ID').val();
            //}
            var Id = $('#ID').val();
            top.wrapper.addTab("打印国标气体", "/UI/PM/PrintCertificate.aspx?Id=" + Id)
        }

        function funcPrintCertOxygen() {
            var analRes = $('#AnalyseRes').combobox('getValue');
            if (analRes == '2' || analRes == undefined) {
                com.message('error', '当前气瓶还未分析完成，请判定是否合格后再打印');
                return;
            }

            if (analRes == '1') {
                com.message('error', '当前气瓶分析结果为不合格，无法打印证书');
                return;
            }
            //var Id = com.get.ID
            //if (Id == undefined) {
            //    Id = $('#ID').val();
            //}
            var Id = $('#ID').val();
            top.wrapper.addTab("打印国标气体", "/UI/PM/PrintCertificateOxygen.aspx?Id=" + Id)
        }

        function funcPrintCertPure() {
            var analRes = $('#AnalyseRes').combobox('getValue');
            if (analRes == '2' || analRes == undefined) {
                com.message('error', '当前气瓶还未分析完成，请判定是否合格后再打印');
                return;
            }

            if (analRes == '1') {
                com.message('error', '当前气瓶分析结果为不合格，无法打印证书');
                return;
            }
            //var Id = com.get.ID
            //if (Id == undefined) {
            //    Id = $('#ID').val();
            //}
            var Id = $('#ID').val();
            top.wrapper.addTab("打印非国标气体", "/UI/PM/PrintCertificatePure.aspx?Id=" + Id)

        }

        function GetTableData() {
            var rows = $("#tbList").datagrid("getRows");
            var arr = new Array();
            for (var i = 0; i < rows.length; i++) {
                var $tr = $("#divTable tr:eq(" + (parseInt(i + 1) + parseInt(rows.length) + 1) + ")");
                var valConc = $tr.find("#AnalyseConcentration").val();
                //转换成百分比
                rows[i]["AnalyseConcentration"] = valConc / 10000;
                rows[i]["AnalyseMethod"] = $tr.find("#AnalyseMethod").combobox("getText");
                rows[i]["AnalyseFile"] = $tr.find("#AnalyseFile").val();
                rows[i]["PrintUnit"] = $tr.find("#PrintUnit").combobox("getValue");
                rows[i]["PrintConcentration"] = $tr.find("#PrintConcentration").combobox("getValue");
                rows[i]["AnalyseNote"] = $tr.find("#AnalyseNote").val(); 
                rows[i]["AnalStandardConc"] = $tr.find("#AnalStandardConc").val();
                rows[i]["AnalStandardBottleCode"] = $tr.find("#AnalStandardBottleCode").val();
                rows[i]["PrintDigitNum"] = $tr.find("#PrintDigitNum").val();
                arr.push(rows[i]);
            }
            return arr;
        }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div style="height: 100%; overflow: auto">
        <div id="master" class="container_12" style="height: auto;">
            <form id="form1">
                <div class="grid_12 val" style="height: 100px; text-align: center;">
                    <textarea id="SweepCode" name="Note" style="width: 800px; height: 80px" placeholder="该区域是扫码区域，需要获取鼠标焦点，即可扫码"></textarea>
                </div>
                <div class="clear"></div>
                <div class="grid_1 lbl" style="text-align: right;">
                    流水号 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="SerialCode" name="SerialCode" disabled="disabled" />
                </div>
                <div class="grid_1 lbl" style="text-align: right;">
                    气瓶编号 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="BottleCode" name="BottleCode" disabled="disabled" />
                </div>

                <div class="grid_1 lbl" style="text-align: right;">
                    分析结论:
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" class="easyui-combobox" id="AnalyseRes" name="AnalyseRes" disabled="disabled" data-options="valueField:'value',textField:'text',data:StaticCombo.BottleAnalyseRes,panelHeight:'auto'" />
                </div>
                <div class="grid_1 lbl" style="text-align: right;">
                    分析日期:
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="AnalyseDate" name="AnalyseDate" disabled="disabled" />
                </div>
                <div class="clear"></div>
                <input type="hidden" id="ID" name="ID" />
                <input type="hidden" id="State" name="State" />
            </form>
        </div>
    </div>
    <div id="divTable" style="height: auto; width: 100%">
        <%--       <div class="easyui-toolbar" style="float: left">
            <a href="#" id="btnSave" onclick="funcSave()" iconcls="icon-save">保存</a>
            <a href="#" id="btnReset" onclick="funcReload()" iconcls='icon-reload'>重置</a>
            <a href="#" id="btnCheck" onclick="funcCheck()" iconcls='icon-table_save'>判定是否合格</a>
            <a href="#" id="btnPrintLabel" onclick="funcPrintLabel()" iconcls='icon-printer'>打印标签</a>
            <%--   <a href="#" id="btnPrintCert" onclick="funcPrintCert()" iconcls='icon-printer'>打印证书</a>
        </div>--%>
        <div id="divToobar" style="background-color: #EFEFEF; overflow: visible">
            <a href="javascript:void(0)" id="btnSave" class="easyui-linkbutton" onclick="funcSave()"
                data-options="iconCls:'icon-save',plain:true">保存</a> &nbsp;&nbsp;
              <a href="javascript:void(0)" id="btnReset" class="easyui-linkbutton" onclick="funcReload()"
                  data-options="iconCls:'icon-reload',plain:true">重置</a> &nbsp;&nbsp;
              <a href="javascript:void(0)" id="btnCheck" class="easyui-linkbutton" onclick="funcCheck()"
                  data-options="iconCls:'icon-table_save',plain:true">判定是否合格</a> &nbsp;&nbsp;
 <%--             <a href="javascript:void(0)" id="btnPrintLabel" class="easyui-linkbutton" onclick="funcPrintLabel()"
                  data-options="iconCls:'icon-printer',plain:true">打印标签</a>--%>

            <a href="javascript:void(0)" id="btnPrintLabel" class="easyui-menubutton"
                data-options="menu:'#MpShowLabel',iconCls:'icon-printer'">打印标签</a>

            &nbsp;&nbsp;
               <a href="javascript:void(0)" id="btnPrintCert" class="easyui-menubutton"
                   data-options="menu:'#MpShow',iconCls:'icon-printer'">打印证书</a>

            &nbsp;&nbsp;
               <a href="javascript:void(0)" id="btnPrintRecord" class="easyui-menubutton"
                   data-options="menu:'#MpRecord',iconCls:'icon-printer'">打印记录</a>
        </div>


        <div id="MpShow" style="width: 120px;">


            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintCert()">国标</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintCertPure()">非国标</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintCertOxygen()">20.8氧气</div>

        </div>

        <div id="MpShowLabel" style="width: 120px;">


            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintLabel(1)">聚光标签</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintLabel(2)">亦恒标签</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintLabel(3)">普通标签</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintLabel(4)">20.8氧气标签</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintLabel(5)">中文名称标签</div>
        </div>

        <div id="MpRecord" style="width: 120px;">


            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintRecord(1)">标签记录</div>
            <div class="menu-sep"></div>
            <div data-options="iconCls:'icon-script_start'" onclick="funcPrintRecord(2)">证书记录</div>


        </div>
        <table id="tbList" title="气瓶气体信息" style="height: auto; width: 100%; margin: 0 auto"></table>
    </div>
</asp:Content>
